package com.weizhizs.assistant.code.config;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang3.StringUtils;

/**
 * @author wutianbin
 * @version 1.0
 * @Time: 2017年5月18日 下午7:29:10
 */
public class PropertiesConfig {

    protected Configuration config;

    public PropertiesConfig() {
        this.config = getConfig();
    }

    private Configuration getConfig() {
        try {
            Configuration config = new PropertiesConfiguration("generator.properties");
            String filename = config.getString("active");
            if (StringUtils.isEmpty(filename)) {
                throw new RuntimeException("获取配置文件失败");
            }

            return new PropertiesConfiguration(filename);
        } catch (ConfigurationException e) {
            throw new RuntimeException("获取配置文件失败");
        }
    }

    protected String[] readStringArray(String fieldName) {
        String value = config.getString(fieldName);
        if (StringUtils.isNotBlank(value)) {
            return value.split("\\|");
        } else {
            return new String[0];
        }
    }

}
